package com.whz.governance.http.ribbon.mvc;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

/**
 * grey test filter supported
 *
 * @author whz
 */
@Configuration
@ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnProperty(name = "generic.ribbon.grey.router.enable", havingValue = "true", matchIfMissing = true)
public class HttpFilterConfiguration {
    @Bean
    public FilterRegistrationBean<HttpGreyTagFilter> registerHttpGreyTagFilter() {
        FilterRegistrationBean<HttpGreyTagFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new HttpGreyTagFilter());
        registration.addUrlPatterns("/*");
        registration.setName("MS_Common_HttpGreyTagFilter");
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return registration;
    }
}